// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   WorkTimeConfController.java

package fy.hr.controller;



import fy.hr.constant.OA2HRConstant;
import fy.util.MyUtil;

import java.io.*;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;

import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.controller.BaseController;

public class WorkTimeConfController extends BaseController
{
	
    private static Log log = LogFactory.getLog(WorkTimeConfController.class);
    private static final String workTimeConf = "fy_view/hr/workTimeConf";
    private final static String inserttime="insert into OATime value(?,?,?,?,?)";
    private final static String updatetime="update OATime set accountID=?,zaoshangshangbanshijian=?,zaoshangxiabanshijian=?,xiawushangbanshijian=?,xiawuxiabanshijian=? where accountID=?";
    private final static String seletetime="selete * from OATime where accountID=?";
    public WorkTimeConfController()
    {
    }

    public ModelAndView  setWorkTime(HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        ModelAndView modelAndView = null;
        if(AppContext.getCurrentUser() != null)
        {
        	long accountID = AppContext.getCurrentUser().getAccountId();
            modelAndView = new ModelAndView(workTimeConf);
            String zaoshangshangbanshijian = request.getParameter("zaoshangshangbanshijian");
            if(zaoshangshangbanshijian == null || "".equals(zaoshangshangbanshijian))
            {
                String filePath = MyUtil.getRealPath(WorkTimeConfController.class) +"../workTimeConf" + accountID;
                
                File file = new File(filePath);
                if(file.exists() && file.isFile() ){
                
	                FileInputStream fis = new FileInputStream(filePath);
	                InputStreamReader isr = new InputStreamReader(fis, "utf-8");
	                BufferedReader br = new BufferedReader(isr);
	                zaoshangshangbanshijian = br.readLine();
	                if(zaoshangshangbanshijian != null && !"".equals(zaoshangshangbanshijian))
	                {
	                    String zaoshangxiabanshijian = br.readLine();
	                    String xiawushangbanshijian = br.readLine();
	                    String xiawuxiabanshijian = br.readLine();
	                    br.close();
	                    modelAndView.addObject("zaoshangshangbanshijian", zaoshangshangbanshijian);
	                    modelAndView.addObject("zaoshangxiabanshijian", zaoshangxiabanshijian);
	                    modelAndView.addObject("xiawushangbanshijian", xiawushangbanshijian);
	                    modelAndView.addObject("xiawuxiabanshijian", xiawuxiabanshijian);
	                }
                }
            } else
            {
                String zaoshangxiabanshijian = request.getParameter("zaoshangxiabanshijian");
                String xiawushangbanshijian = request.getParameter("xiawushangbanshijian");
                String xiawuxiabanshijian = request.getParameter("xiawuxiabanshijian");
                String filePath = MyUtil.getRealPath(WorkTimeConfController.class) +"../workTimeConf" + accountID;
                FileOutputStream fos = new FileOutputStream(filePath);
                OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
                osw.write((new StringBuilder(String.valueOf(zaoshangshangbanshijian))).append("\n").append(zaoshangxiabanshijian).append("\n").append(xiawushangbanshijian).append("\n").append(xiawuxiabanshijian).append("\n").toString());
                osw.flush();
                osw.close();
                //写到内存中
                String[] workTime = new String[]{ zaoshangshangbanshijian, zaoshangxiabanshijian,xiawushangbanshijian,xiawuxiabanshijian};
                OA2HRConstant.setWorkTime(workTime, String.valueOf(accountID));
                
                modelAndView.addObject("zaoshangshangbanshijian", zaoshangshangbanshijian);
                modelAndView.addObject("zaoshangxiabanshijian", zaoshangxiabanshijian);
                modelAndView.addObject("xiawushangbanshijian", xiawushangbanshijian);
                modelAndView.addObject("xiawuxiabanshijian", xiawuxiabanshijian);
                modelAndView.addObject("message", "\u4FDD\u5B58\u6210\u529F");
            }
        }
        return modelAndView;
    }

}
